package com.integralPerformance.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.integralPerformance.common.Result;
import com.integralPerformance.pojo.entity.PointsCriteria;
import com.integralPerformance.pojo.entity.ServiceBase;
import com.integralPerformance.pojo.form.add.AddServiceBase;
import com.integralPerformance.pojo.form.update.UpdateServiceBase;
import com.integralPerformance.pojo.query.ServiceBaseQuery;
import com.integralPerformance.pojo.vo.BaseVo;
import com.integralPerformance.service.ServiceBaseService;
import com.integralPerformance.mapper.ServiceBaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author admin
* @description 针对表【service_base(公共服务岗位及积分维护表)】的数据库操作Service实现
* @createDate 2024-03-14 17:04:49
*/
@Service
public class ServiceBaseServiceImpl extends ServiceImpl<ServiceBaseMapper, ServiceBase>
    implements ServiceBaseService{

    @Autowired
    ServiceBaseMapper serviceBaseMapper;

    @Override
    public Result<BaseVo<ServiceBase>> getServiceBase(ServiceBaseQuery serviceBaseQuery) {

        Page<ServiceBase> page = new Page<>(serviceBaseQuery.getCurrentPage(), serviceBaseQuery.getPageSize());
        Page<ServiceBase> result = serviceBaseMapper.getServiceBase(page, serviceBaseQuery);

        BaseVo<ServiceBase> criteriaBaseVo = new BaseVo<>();
        criteriaBaseVo.setCurrentPage(serviceBaseQuery.getCurrentPage());
        criteriaBaseVo.setPageSize(serviceBaseQuery.getPageSize());
        criteriaBaseVo.setAllPages(result.getPages());
        criteriaBaseVo.setAllRecordNum(result.getTotal());
        criteriaBaseVo.setRecords(result.getRecords());

        return Result.success(criteriaBaseVo);

    }

    @Override
    public Result<String> updateServiceBase(UpdateServiceBase updateServiceBase) {
        serviceBaseMapper.updateById(updateServiceBase);
        return Result.success("更新成功");
    }

    @Override
    public Result<String> addServiceBase(AddServiceBase addServiceBase) {
        ServiceBase serviceBase = new ServiceBase();
        BeanUtil.copyProperties(addServiceBase,serviceBase);
        serviceBaseMapper.insert(serviceBase);
        return Result.success("添加成功");
    }

    @Override
    public Result<String> deleteServiceBaseById(String id) {
        serviceBaseMapper.deleteById(id);
        return  Result.success("删除成功");
    }

    @Override
    public Result<String> deleteServiceBaseByIds(List<Long> ids) {
        serviceBaseMapper.deleteBatchIds(ids);
        return Result.success("删除成功");
    }
}




